package com.atguigu.sparkcore.day02.kv

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * Author atguigu
 * Date 2020/10/28 15:31
 */
object GroupByKey {
    def main(args: Array[String]): Unit = {
        val conf: SparkConf = new SparkConf().setAppName("SparkCoreTest").setMaster("local[*]")
    
        //2.创建SparkContext，该对象是提交Spark App的入口
        val sc: SparkContext = new SparkContext(conf)
    
        //3具体业务逻辑
        //3.1 创建第一个RDD
        val rdd1 = sc.makeRDD(List(("a", 1), ("b", 5), ("a", 2), ("a", 7), ("a", 5), ("b", 2)), 2)
        val rdd2: RDD[(String, Iterable[Int])] = rdd1.groupByKey
        rdd2.collect().foreach(println)
        
        sc.stop()
    }
}
